package top.zuli.package01.class13;

/**
 * 通过实现Runnable接口创建线程1、线程2，并分别打印1-100的偶数，1-100的奇数
 */
public class ThreadDemo6 {
    public static void main(String[] args) {
        //创建线程1
        Thread thread1 = new Thread(new Runnable1(),"线程1");
        //创建线程2
        Thread thread2 = new Thread(new Runnable2(),"线程2");
        //启动线程
        thread1.start();
        thread2.start();
    }
}
class Runnable1 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <=100; i++) {
            if(i%2==0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}
class Runnable2 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i <=100; i++) {
            if(i%2!=0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName()+":"+i);
            }
        }
    }
}